home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.9 KB | 277 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: HelloFrm.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Hello.hpp"
-
- #ifndef HELLOFRM_H
- #include "HelloFrm.h"
- #endif
-
- #ifndef HELLOPRT_H
- #include "HelloPrt.h"
- #endif
-
- #ifndef HELLOCMD_H
- #include "HelloCmd.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfhello
- #endif
-
- //========================================================================================
- // CHelloFrame class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame constructor
- //----------------------------------------------------------------------------------------
- CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloPart* helloPart)
- : FW_CFrame(ev, odFrame, presentation, helloPart)
- {
- fHelloPart = helloPart;
-
- SetDroppable(ev, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame destructor
- //----------------------------------------------------------------------------------------
- CHelloFrame::~CHelloFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CHelloFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop = FW_CFrame::CanAcceptDrop(ev, dragInfo);
-
- // ----- Test for 'TEXT' also -----
- #ifdef FW_BUILD_MAC
- if (!acceptDrop)
- {
- for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0)) // 'TEXT' on Scrap
- return TRUE;
- }
- #endif
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean result = FALSE;
-
- if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
- {
- result = this->Drag(ev, theMouseEvent);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoMenuEvent
- //----------------------------------------------------------------------------------------
- FW_Boolean CHelloFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Boolean menuHandled = FALSE;
-
- switch (theMenuEvent.GetCommandID(ev))
- {
- case kODCommandAbout:
- menuHandled = this->DoAboutBox();
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- if (hasMenuFocus)
- {
- //---- Set up the About menu item ----
- FW_CString32 aboutString;
- fHelloPart->GetResourceString(kAboutBoxStrings, kAboutMenuString, aboutString);
- menuBar->SetItemString(ev, kODCommandAbout, aboutString);
- menuBar->EnableCommand(ev, kODCommandAbout, TRUE);
-
- //---- Set up the Edit menu items ----
- #ifdef FW_BUILD_MAC
- menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
- #endif
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoAboutBox
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloFrame::DoAboutBox()
- {
- FW_CString32 str1, str2;
-
- fHelloPart->GetResourceString(kAboutBoxStrings, kHelloPartString, str1);
- fHelloPart->GetResourceString(kAboutBoxStrings, kCreditString, str2);
-
- FW_CAlert::DoAlert(str1, str2, FW_kOK, FW_kNoteAlert, FW_kDefaultButton1, FALSE);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CHelloFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext fc(ev, this, odFacet, invalidShape);
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
-
- FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- FW_CRect helloRect = GetBounds(ev);
-
- FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_PInk(FW_kRGBBlack));
-
- // If this is a root part, draw the text centered horizontally and vertically.
- // If it's an embedded part, center the text horizontally, with word wrap and clipping.
- FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
- if (!this->IsRoot(ev))
- {
- options |= FW_kTextBoxWordWrap;
- options |= FW_kTextBoxClipToBox;
- }
- FW_CTextBoxShape::RenderTextBox(
- fc,
- fHelloPart->GetTextData(),
- helloRect,
- FW_PFont(FW_kSystemFont, FW_kPlain, FW_IntToFixed(12)),
- options);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
-
- void CHelloFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewEditCommand
- //----------------------------------------------------------------------------------------
-
- FW_CEditCommand* CHelloFrame::NewEditCommand(Environment* ev, ODCommandID commandID)
- {
- return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloPart, this));
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CHelloFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame)
- {
- return FW_NEW(CHelloDragCommand, (ev, fHelloPart, theFrame));
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- return FW_NEW(CHelloDropCommand, (ev, fHelloPart, this, dropInfo, odFacet, dropPoint));
- }
-